package jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class RegDemo {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入姓名:");
        String un = scan.nextLine();
        System.out.println("请输入密码:");
        String pw = scan.nextLine();
        System.out.println("请输入昵称:");
        String nn = scan.nextLine();
        System.out.println("请输入年龄:");
        int a = Integer.parseInt(scan.nextLine());//scan.nexInt()不会读回车
        try(Connection conn = DBUtil.getConnection();) {
            Statement statement = conn.createStatement();
            String sql = "INSERT INTO user(username,password,nickname,age) " + "VALUE('"+un+"','"+pw+"','"+nn+"','"+a+"')";
            int num = statement.executeUpdate(sql);
            System.out.println("注册成功");
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
